package com.cola.springmvc.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Grup:com.cola.springmvc.controller.interceptor
 * @Auther:cola
 * @Data:2021/5/8-2021-05-23:31
 * @version:1.0
 */
public class MyInterceptor1 implements HandlerInterceptor {
    /*
    *
    * 在执行handler之前执行,用于身份校验,权限认证
    * 返回true表示放行
    * 返回false表示拦截
    * */

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("preHandle");
        return true;
    }

    /*
    * 在执行Handler时返回ModelAndView之前执行
    * 如果想要向页面提供一些公共的数据或者是一些公用的配置信息,可以考虑使用这里的ModelAndView对象
    * */
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("postHandle");
    }
    /*
    * 在执行Handler之后
    * 日志,系统性能分析
    * */
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.out.println("afterCompletion");
    }
}
